<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>参与投票</title>
<link type="text/css" rel="stylesheet" href="css/style.css" />
	<script src="http://47.106.66.89:8080/js/vue.min.js"></script>
	<script src="http://47.106.66.89:8080/js/axios.min.js"></script>
	<link  href="http://47.106.66.89:8080/js/ele-2.15.7/theme-chalk/index.css" rel="stylesheet">
	<script src="http://47.106.66.89:8080/js/ele-2.15.7/index.js"></script>
	<script src="/user/js/login.js"></script>
	<script src="/vcode/js/vcode.js"></script>
	<script src="/js/vote.js"></script>
</head>
<body>
<div id="app">
	<vote>
		<div id="vote" class="wrap">
			<h2>参与投票</h2>
			<ul class="list">
				<li>
					<h4>{{vote.vname}}</h4>
					<p class="info">共有 {{vote.items.length}} 个选项，已有 {{vote.userCnt}} 个网友参与了投票。</p>
					<form method="post" action="Vote!save.action">
						<input type="hidden" name="entityId" value="103"/>
						<ol>
							<li v-for=" item in vote.items">
								<input :type="vote.vtype=='单选'?'radio':'checkbox'"
									   name="options" :value="item.id"
										v-model="iids"/>
								{{item.iname}}
							</li>
						</ol>
						<p class="voteView">
							<input type="image" src="images/button_vote.gif"
								@click.prevent="commit"/>
							<a :href="'view.html?id='+vote.id">
								<img src="images/button_view.gif" />
							</a></p>
					</form>
				</li>
			</ul>
		</div>
	</vote>
</div>

<script>
	var v = new Vue({
		el:"#app",
		data:{
			vote:{items:[]},
			iids:[]
		},
		created(){
			axios.get("/vote/tpVote/queryById" + location.search).then(res=>{
				this.vote = res.data;
			})
		},
		methods:{
			commit(){
				let p = new URLSearchParams();
				p.append("vid",this.vote.id);
				if(this.vote.vtype=='多选'){
					this.iids.forEach(iid=>{
						p.append("iids", iid);
					});
				} else {
					p.append("iids", this.iids);
				}
				axios.post("/vote/tpRecord/commit", p).then(res=>{
					if(res.data.code == 1){
						location.href="view.html?id="+this.vote.id;
					} else {
						this.$alert(res.data.msg);
					}
				})
			}
		}

	})
</script>
</body>
</html>
